var $table = $("#table");
var $remove = $("#removeBtn");
var $update = $("#updateBtn");
var $search = $("#searchBtn");
var selections = []

//$(this).serialize()
$(function () {
    tableList(columns)
})

var columns = [{
    checkbox: true
}, {
    field: 'name',
    title: '分类名称',
    align: 'center',
}]

$remove.click(function () {
    confirmAlert(function () {
        var ids = getIdSelections();
        ajaxJson("/admin/classify/ajax/delete", {"ids": ids.toString()}, function (res) {
            if (res.status) {
                $table.bootstrapTable('refresh')
                $remove.prop('disabled', true);
                $update.prop('disabled', true);
            }
        })
    })
})

$update.click(function () {
    var ids = getIdSelections()
    if (ids){
        location.href = "/admin/classify/save?id=" + ids[0]
    }
})

function getIdSelections() {
    return $.map($table.bootstrapTable('getSelections'), function (row) {
        return row.id
    })
}

$table.on('check.bs.table uncheck.bs.table ' +
    'check-all.bs.table uncheck-all.bs.table',
    function () {
        $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
        $update.prop('disabled', !$table.bootstrapTable('getSelections').length);

        // save your data, here just save the current page
        selections = getIdSelections()
        // push or splice the selections if you want to save all data selections
    })

$search.click(function () {
    $table.bootstrapTable('refresh')
})